logo

Crate ccm

source · []
Expand description

Counter with CBC-MAC (CCM): Authenticated Encryption and Associated Data (AEAD) algorithm generic over block ciphers with block size equal to 128 bits as specified in RFC 3610.

Usage

Simple usage (allocating, no associated data):

use aes::Aes256;
use ccm::{
    aead::{Aead, KeyInit, OsRng, generic_array::GenericArray},
    consts::{U10, U13},
    Ccm,
};

// AES-256-CCM type with tag and nonce size equal to 10 and 13 bytes respectively
pub type Aes256Ccm = Ccm<Aes256, U10, U13>;

let key = Aes256Ccm::generate_key(&mut OsRng);
let cipher = Aes256Ccm::new(&key);
let nonce = GenericArray::from_slice(b"unique nonce."); // 13-bytes; unique per message
let ciphertext = cipher.encrypt(nonce, b"plaintext message".as_ref())?;
let plaintext = cipher.decrypt(nonce, ciphertext.as_ref())?;
assert_eq!(&plaintext, b"plaintext message");

This crate implements traits from the aead crate and is capable to perfrom encryption and decryption in-place wihout relying on alloc.

Re-exports

pub use aead;

Modules

Type aliases for many constants.

Structs

CCM instance generic over an underlying block cipher.

Error type.

Traits

Authenticated Encryption with Associated Data (AEAD) algorithm core trait.

In-place stateless AEAD trait.

Types which can be initialized from key.

Types which use key for initialization.

Trait implemented for valid nonce sizes, i.e. U7, U8, U9, U10, U11, U12, and U13.

Trait implemented for valid tag sizes, i.e. U4, U6, U8, U10, U12, U14, and U16.

Type Definitions

Key used by KeySizeUser implementors.

CCM nonces

CCM tags